import {getusertInfo} from "../../api/api";
import  {getimg,getheaderImg} from "../../api/api";

export default {
    namespaced:true,
    state:{
        //是否登录
        isLogin:false,
        //个人信息
        UserInfo:[],
        imgurl:""
    },
    mutations:{
        changeIsLogin(state,login){
            state.isLogin = login;
        },
        changeUserInfo(state,userInfo1){
            state.UserInfo = userInfo1;
        },
        changeimgUrl(state,n) {
            state.imgurl = n;
        }
    },
    actions:{
        getUserInfo(context){
            getusertInfo().then(res=>{
                // console.log(res);
                if(res.code==0) {
                    context.commit("changeIsLogin", true);
                    context.commit("changeUserInfo", res.data);
                    // console.log(context.state.UserInfo)
                }else {
                    context.commit("changeIsLogin", false);
                    this.$toast(res.msg)
                }
            })
        },
        getImguser({dispatch},payload){
            getimg(payload.file,payload.text).then(res=>{
                console.log(res);
                dispatch("getUserInfo")
            })
        },
        getHeaderIm({dispatch},file){
            getheaderImg(file).then(res=>{
                console.log(res);
                dispatch("getUserInfo");
            })
        },
        getImgUrl({commit},payload){
            getimg(payload.file,payload.text).then(res=>{
                // console.log(res);
               commit("changeimgUrl",res.url);
            })
        }

    },
    getters:{


    },

}